package com.ubb.dbms.domain.queryData;

public class Condition {
	private Object leftOperand;
	private Operator operator;
	private Object rightOperand;
	
	public Object getLeftOperand() {
		return leftOperand;
	}
	public void setLeftOperand(Object leftOperand) {
		this.leftOperand = leftOperand;
	}
	public Operator getOperator() {
		return operator;
	}
	public void setOperator(Operator operator) {
		this.operator = operator;
	}
	public Object getRightOperand() {
		return rightOperand;
	}
	public void setRightOperand(Object rightOperand) {
		this.rightOperand = rightOperand;
	}
	
	
	public int compareValues() {
		if (this.leftOperand instanceof Integer) {
			int intLeftOperand = (Integer) this.leftOperand;
			int intRightOperand = Integer.parseInt(this.rightOperand.toString());
			if (intLeftOperand == intRightOperand) {
				return 0;			// leftOperand equals with rightOperand
			} else if (intLeftOperand > intRightOperand) {
				return 1;			// leftOperand is greater than rightOperand
			} else {
				return -1;			// leftOperand is lower than rightOperand
			}
		} else {
			String stringLeftOperand = this.leftOperand.toString();
			String stringRightOperand = this.rightOperand.toString();
			return stringLeftOperand.compareTo(stringRightOperand);
		}
	}
	
	public boolean evaluate() {
		int comparedResult = compareValues();
		
		switch (operator) {
		case EQUAL:
			return comparedResult == 0;
		case NOT_EQUAL:
			return comparedResult != 0;
		case GREATHER_OR_EQUAL:
			return comparedResult == 0 || comparedResult > 0;
		case LOWER_OR_EQUAL:
			return comparedResult == 0 || comparedResult < 0;
		case GREATHER:
			return comparedResult > 0;
		case LOWER:
			return comparedResult < 0;
		default:
			return false;
		}
	}
}
